﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.TextBox;

namespace DXApplication1月报表
{
    public partial class XtraForm修改密码 : DevExpress.XtraEditors.XtraForm
    {
        public XtraForm修改密码()
        {
            InitializeComponent();
        }

        private void simpleButton修改密码_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrWhiteSpace(textEdit用户名.Text.Trim()) == true)
            {
                XtraMessageBox.Show("请输入用户名");
                return;
            }
            if (string.IsNullOrWhiteSpace(textEdit原密码.Text.Trim()) == true)
            {
                XtraMessageBox.Show("请输入原密码");
                return;
            }

            string sql = $"select * from [Z_用户名密码] where 用户名 = '{textEdit用户名.Text.Trim()}' and 密码 = '{textEdit原密码.Text.Trim()}'";
            DataTable dt = new DataTable();
            dt = SqlHelper.SqlHelper.ExecuteDataset(sql).Tables[0];
            if (dt != null && dt.Rows.Count > 0)
            {
                sql = $"  update Z_用户名密码 set 密码 = '{textEdit新密码.Text.Trim()}' where 用户名 = '{textEdit用户名.Text.Trim()}' and 密码 = '{textEdit原密码.Text.Trim()}'";
                int r = SqlHelper.SqlHelper.ExecuteNonQuery(sql);
                if (r > 0)
                {
                    XtraMessageBox.Show("修改成功");
                    this.Close(); 
                }
                else
                {
                    XtraMessageBox.Show("修改失败");
                }
            }
            else
            {
                XtraMessageBox.Show("账号或密码错误");
            }
        }
    }
}